// @author: caoshi
// @date: 2021-05-08 21:12
package main

import (
	"fmt"
	"net/http"
	"strings"
)

/**
	解析请求头和请求参数
 */
func params(writer http.ResponseWriter, req *http.Request) {
	header := req.Header
	fmt.Println(header)
	fmt.Println(header["Accept-Encoding"])
	fmt.Println(len(header["Accept-Encoding"]))

	fmt.Println("-----------------------------")
	for _, n := range strings.Split(header["Accept-Encoding"][0], ", ") {
		fmt.Println(strings.TrimSpace(n))
	}

	fmt.Println("-----------------------------")

	// 解析请求参数
	err := req.ParseForm()
	if err != nil {
		fmt.Println("err = ", err)
		return
	}
	fmt.Println(req.Form)	// 先解析成form
	fmt.Println(req.Form["name"][0])

	fmt.Println(req.FormValue("name"))


}

func main() {
	server := http.Server{
		Addr: "localhost:8080",
	}

	http.HandleFunc("/params", params)

	defer server.Close()
	err := server.ListenAndServe()
	if err != nil {
		fmt.Println("err = ", err)
		return
	}
}





